import { Router } from "express";
import {
  register,
  login,
  my,
  update,
  avatar,
  oInfo,
  videos,
  follow,
  unfollow,
  follows,
  fans,
  collects,
  likes,
} from "../controllers/userController.js";
import {
  registerValidator,
  loginValidator,
  updateValidator,
} from "../middleware/validator/userValidator.js";
import { verifyToken } from "../utils/jwt.js";
// 文件上传
import multer from "multer";
const upload = multer({ dest: "public/uploads/avatar" });

const router = Router();
router
  .post("/register", registerValidator, register)
  .post("/login", loginValidator, login)
  .get("/my", verifyToken(), my)
  .patch("/", verifyToken(), updateValidator, update)
  .post("/avatar", verifyToken(), upload.single("avatar"), avatar)
  .get("/:uId", verifyToken(false), oInfo) // 获取其他用户信息
  .get("/:uId/videos", verifyToken(false), videos) // 获取用户发布的视频
  .post("/follow/:uId", verifyToken(), follow) // 关注
  .post("/unfollow/:uId", verifyToken(), unfollow) // 取消关注
  .get("/:uId/follows", verifyToken(), follows) // 获取关注列表
  .get("/:uId/fans", verifyToken(), fans) // 获取粉丝列表
  .get("/:uId/collects", verifyToken(), collects) // 获取收藏视频列表
  .get("/:uId/likes", verifyToken(), likes); // 获取点赞视频列表

export default router;
